const mongoose = require("mongoose");
const Product = require("./models/Products"); // 替换为你的 Product 模型文件的实际路径

// MongoDB 连接字符串
const uri = 'mongodb://xsh:123456@localhost:27017/petshop'; // 替换为你的连接字符串
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });

const createTestData = async () => {
    // 测试数据
    const testData = [
        { title: "Product 1", price: 10.99, description: "Description for product 1", category: "Category1", image: "url/to/image1.jpg" },
        { title: "Product 2", price: 20.99, description: "Description for product 2", category: "Category2", image: "url/to/image2.jpg" },
        { title: "Product 3", price: 30.99, description: "Description for product 3", category: "Category3", image: "url/to/image3.jpg" }
    ];

    // 插入数据
    try {
        for (const data of testData) {
            const product = new Product(data);
            await product.save();
        }
        console.log("Test data inserted successfully.");
    } catch (error) {
        console.error("Error inserting test data:", error);
    }
};

createTestData();
